/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package src.model;

import java.sql.*;

/**
 *
 * @author camila
 */
public class Conexao {

	// --- Cria atributos ---
	private static final String driver = "org.apache.derby.jdbc.EmbeddedDriver";
	private static final String url = "jdbc:derby:/home/camila/Repositorio/Organizador_Tarefas/AgendaNetBeans/db_tarefas;create=true";
	public static Connection con;
	private static Conexao conexao = null;


	private Conexao () {
		// --- Realiza conex�o com o banco de dados ---
		try {
			Class.forName (driver);
			con = DriverManager.getConnection (url);
		} catch (SQLException se) {
			printSQLException(se);
		} catch (Exception ex) {
			System.exit (0);
		}
	}

	public static synchronized Conexao getConexao () {

		if (conexao == null) {
			conexao = new Conexao ();
		}
		return conexao;
	}

	// ---  M�todo que trata a exce��o SQL ---
	private static void printSQLException (SQLException se) {
		while (se != null) {
			System.out.print ("SQLException: State:   " + se.getSQLState ());
			System.out.println ("Severity: " + se.getErrorCode ());
			System.out.println (se.getMessage ());

			se = se.getNextException();
		}
	}

}
